// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short did_talk = 0;
short res_switch = 0;
short sum1 = 0;
short sum2 = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Vabna-Eye");
	set_boss_level(ME,2);
	
	place_particle_num(ME,18,12,10);		
	set_resistance(ME,1,95);
	set_resistance(ME,2,95);
	set_resistance(ME,6,95);
	
	break;

beginstate DEAD_STATE;
	sf(71,7,1);
break;

beginstate START_STATE; 
	if ((did_talk == 0) && (get_attitude(ME) < 10) && (get_nearest_party_char(6) >= 0)) {
		did_talk = 1;
		set_attitude(ME,10);
		talk_no_exit(70);
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}


	if ((get_attitude(ME) >= 10) && (did_talk > 0)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
		
	if ((res_switch == 0) && (get_health(ME) < get_max_health(ME) / 2)) {
		res_switch = 1;
		
		set_resistance(ME,0,95);
		set_resistance(ME,1,20);
		set_resistance(ME,2,20);
		set_resistance(ME,6,20);
		
		clean_off_particles(ME);
		place_particle_num(ME,19,12,10);		
	
		begin_talk_mode(8);
		}
	
	if ((sum1 == 0) && (get_health(ME) < (get_max_health(ME) * 3) / 4)) {
		sum1 = 1;
		
		kill_object(141,0);
		
		print_str_color("Vabna-Eye mutters a word of command.",3);
		print_str_color("  One of the Shaping vats opens.",3);

		spawn_creature(22);
		place_particle_num(30,10,7,10);
		set_boss_level(30,2);
		force_char_status(30,1,10);
		set_name(30,"Bladewarded Gamma");
		place_particle_num(30,19,12,10);		
		}
	
	if ((sum2 == 0) && (get_health(ME) < (get_max_health(ME) * 1) / 3)) {
		sum2 = 1;
		
		kill_object(142,0);
		
		print_str_color("Vabna-Eye mutters a word of command.",3);
		print_str_color("  One of the Shaping vats opens.",3);

		spawn_creature(23);
		place_particle_num(31,10,7,10);
		set_boss_level(31,2);
		force_char_status(31,1,10);
		set_name(31,"Runewarded Gamma");
		place_particle_num(31,18,12,10);		
		}
		
	do_attack();
break;

beginstate TALKING_STATE;
		print_str("Talking: The eyebeast glares at you.");

break;